<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="项目名称" prop="bindName">
        <el-input
          v-model="queryParams.bindName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="bindList">
      <!-- 添加序号列 -->
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center"
        index-method="indexMethod"
      />
      <el-table-column label="项目编号" align="center" prop="bindCode" />
      <el-table-column label="项目名称" align="center" prop="bindName" />
      <el-table-column label="招标方式" align="center" prop="bindMethod">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.pur_methods"
            :value="scope.row.bindMethod"
          />
        </template>
      </el-table-column>

      <el-table-column label="项目负责人" align="center" prop="bindHeader">
        <template slot-scope="scope">
          <span>{{ scope.row.bindHeader || "————" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.pur_bind_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="checkDetails(scope.row)"
            v-show="scope.row.status > 1"
            v-hasPermi="['purs:bind:edit']"
            >进入项目</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-show="scope.row.status == 1"
            v-hasPermi="['purs:bind:edit']"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['purs:bind:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listBind,
  getBind,
  delBind,
  addBind,
  updateBind,
} from "@/api/purs/bind";

export default {
  name: "Bind",
  dicts: ["pur_methods", "pur_bind_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招标项目表格数据
      bindList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bindName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    /** 进入项目*/
    checkDetails(row) {
      this.$tab.closeOpenPage({
        path: "/details/bind",
        query: {
          bind: row,
        },
      });
    },

    /**编辑 */
    handleUpdate(row) {
      this.$tab.closeOpenPage({
        path: "/update/bind",
        query: {
          bind: row,
        },
      });
    },
    /** 查询招标项目列表 */
    getList() {
      this.loading = true;
      listBind(this.queryParams).then((response) => {
        this.bindList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    indexMethod(index) {
      // 根据需要自定义序号生成方式，这里只是简单返回索引+1
      return index + 1;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bindCode: null,
        bindMethod: null,
        bindName: null,
        bindHeader: null,
        status: null,
        isMust: null,
        examMethod: null,
        bindUnit: null,
        bindPerson: null,
        phone: null,
        email: null,
        binderAddr: null,
        publicTime: null,
        endTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const bindCodes = row.bindCode || this.ids;
      this.$modal
        .confirm('是否确认删除招标项目编号为"' + bindCodes + '"的数据项？')
        .then(function () {
          return delBind(bindCodes);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
